﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sundry.App_Start
{
    /// <summary>
    /// 判断是否登陆
    /// </summary>
    public class AdminLoginAuthor : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool skipAuthorization = filterContext.ActionDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true)
                                     || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(NoNeedLogin), inherit: true);
            if (skipAuthorization)
            {
                return;
            }
            //检查是否登录
            if (!Sundry.App_Start.Common.UserCookie.AdminCheckLogin())
            {
                filterContext.Result = new RedirectResult("~/Admin/Account/Login", true);
            }

            base.OnActionExecuting(filterContext);
        }
    }
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class NoNeedLogin : Attribute
    {

    }
}